package com.example.mymatch.controller;

import com.example.mymatch.model.Busi;
import com.example.mymatch.service.IBusiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * BusiController层
 * 编写者：杨滢
 */


@Api(tags = "出差")
@RestController
public class BusiController {
    @Autowired
    private IBusiService busiService;//对某个业务服务的内容进行定义规范  编写者：杨滢

    @ApiOperation(value = "查询所有出差信息",notes = "获取出差信息返回json字符串")
    @RequestMapping("/getStr12")
    public String getBusi(){
        return "My busi";
    }
    @CrossOrigin
    @ApiOperation(value = "对出差信息的添加方法")
    @GetMapping("/addBusi")
    public int addBusi(Busi busi){
        System.out.println("进入添加出差信息接口");
        return busiService.insertBusi(busi);
    }

    @GetMapping("getAll12")
    @ApiOperation(value = "对出差信息的查询方法")
    public List<Busi> getAllBusi(Busi busi){
        System.out.println("进入查询方法");

        List<Busi> listBusi=busiService.getAllBusi(busi);

        return listBusi;
    }

    @PutMapping("/editBusi")
    @ApiOperation(value = "对出差信息的修改方法")
    public int EditBusi(@RequestBody Busi busi){
        System.out.println("进入出差修改方法");
        return busiService.updateBusi(busi);
    }

    @GetMapping("/delBusi")
    @ApiOperation(value = "对出差信息的删除方法")
    public int Delete(int id){
        System.out.println("进入出差删除方法");
        int returnValue=0;
        if (id!=0){
            Busi busi=new Busi();
            busi.setId(id);
            returnValue= busiService.deleteBusi(busi);
        }
        return returnValue;
    }

    @GetMapping("/getOne12")
    @ApiOperation(value = "对单条出差信息的查询方法")
    public  Busi getBusi(int id){
        Busi busi=new Busi();
        System.out.println("进入出差查询方法");
        if (id!=0){
            Busi busi1=new Busi();
            busi1.setId(id);
            busi=busiService.getBusi(busi1);
            System.out.println("返回的数据集合为："+busi.getBusiName());
        }
        return busi;
    }
}
